package chapter8;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

class A {
    public boolean equals(Object object) {
        return true;
    }
}

class B {
    public int hashCode() {
        return 1;
    }
}

class C {
    public int hashCode() {
        return 2;
    }

    public boolean equals(Object obj) {
        return true;
    }
}

/**
 * 声明三个类，分别重写equals和hashCode方法，然后添加到set集合中，
 * 通过添加的结果判断set集合判断重复的逻辑
 * set判断集合是根据equals方法返回相等，并且hashCode相等
 */
public class HashSetTest {
    public static void main(String[] args) {
        HashSet books = new HashSet();
        books.add(new A());
        books.add(new A());
        books.add(new B());
        books.add(new B());
        books.add(new C());
        books.add(new C());
        System.out.println(books);
    }
}
